package cn.deschen.search.index.adCreative;

import cn.deschen.biz.dto.search.media.AdSlot;
import cn.deschen.search.index.IndexObject;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @Author hanbin_chen
 * @Description 创意广告数据，与索引关联
 * @DateTime 2021/6/5 19:57
 * @Version V1.0.0
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class AdCreativeObject extends IndexObject<AdCreativeObject> {

    @ApiModelProperty(value = "创意广告主键id")
    private Long id;

    @ApiModelProperty(value = "标记当前记录所属用户")
    private Long userId;

    @ApiModelProperty(value = "创意名称")
    private String creativeName;

    @ApiModelProperty(value = "物料类型(image-图片, video视频)")
    private String materialType;

    @ApiModelProperty(value = "物料子类型(图片: bmp, jpg 视频:mp3, avi)")
    private String childMaterialType;

    @ApiModelProperty(value = "高度")
    private Integer height;

    @ApiModelProperty(value = "宽度")
    private Integer width;

    @ApiModelProperty(value = "物料大小, 单位是 KB")
    private Long size;

    @ApiModelProperty(value = "持续时长, 只有视频才不为 0")
    private Integer duration;

    @ApiModelProperty(value = "审核状态(auditing-审批中  pass-审核通过 be_refused-被打回拒绝)")
    private String auditStatus;

    @ApiModelProperty(value = "物料地址")
    private String url;

    /**
     * 匹配广告
     *
     * @param target    待匹配广告
     * @param condition 匹配条件
     * @return
     */
    public boolean matchCreativeAdSlot(AdSlot condition) {

        return matchRule(this.getMaterialType(), condition.getMaterialType())
                && matchRule(this.getChildMaterialType(), condition.getChildMaterialType())
                && matchRule(this.getHeight(), condition.getHeight())
                && matchRule(this.getWidth(), condition.getWidth())
                && matchRule(this.getSize(), condition.getSize())
                && matchRule(this.getDuration(), condition.getDuration());

    }

    /**
     * @param a
     * @param b
     * @return
     */
    private boolean matchRule(Object a, Object b) {
        if (null == b) {
            return true;
        }
        if (a != null && a.equals(b)) {
            return true;
        }
        return false;
    }
}
